package com.sunfeng.netty.heima.day02.promise;

import io.netty.channel.DefaultEventLoop;
import io.netty.util.concurrent.DefaultPromise;
import lombok.extern.slf4j.Slf4j;

/**
 * @ClassName Demo05
 * @Description TODO
 * @Author 孙峰
 * @Date 2022/10/25 14:33
 */
@Slf4j
public class Demo05 {
    public static void main(String[] args) {
        DefaultEventLoop eventExecutors = new DefaultEventLoop();

        DefaultPromise<Integer> promise = new DefaultPromise<>(eventExecutors);
        promise.addListener(future -> {
            log.debug("result:{}", future.isSuccess() ? future.getNow() : future.cause());
        });

        eventExecutors.execute(() -> {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
          //  RuntimeException e = new RuntimeException("error...");
           // log.debug("set failure, {}", e.toString());
           // promise.setFailure(e);
            promise.setSuccess(100);
        });

        log.debug("start...");
        eventExecutors.shutdownGracefully();
    }
}
